
//return 字符串长度
function returnLength(val){         
    var val = $.trim(val);
    return len = val.length;
}
//验证 汉字姓名
function isUserName(username){
    var pattern = /[\u4e00-\u9fa5]{2,14}$/;
    return pattern.test( $.trim(username) );
    
}
//验证手机号码
function isPhoneNo(phonenum){ 
    var pattern = /^1[34578]\d{9}$/;
    return pattern.test( $.trim(phonenum) ); 
}
//验证身份证 
function isCardNo(card) {           
    var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
    return pattern.test( $.trim(card) ); 
} 
//验证身份证
function cardIdVerify(id) {
    if (id.length != 18) {
        return false;
    }
    var idCard_base = id.substr(0, 17);
    var verify_code = id.substr(17, 1);
    var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
    var verify_code_list = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2', 'x'];
    var total = 0;
    for (var i = 0; i < 17; i++) {
        var index = i;
        total += idCard_base.substr(index, 1) * factor[index];
    }
    var mod = total % 11;
    if (verify_code == verify_code_list[mod]) {

        return true;

    } else {
        return false;
    }
}
//密码 匹配6到14位的字母和数字组成
function isPassword(pass){          
    var pattern = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,14}$/;
    return pattern.test( $.trim(pass) );
}
//邮箱 
function isEmail(email){             
    var pattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-z]{2,4})+$/;
    return pattern.test( $.trim(email) );
}
//根据身份证判断性别 都以18位第二代身份证
function matchSex(cardnum){
    var sexnum = cardnum.substr(16,1);
    return (sexnum%2)==1?1:2;   //1:男   2：女
}
//根据身份证匹配生日 都以18位第二代身份证requestAPi.js
function matchBirthday(cardnum){
    var year = cardnum.substr(6,4);
    var month = cardnum.substr(10,2);
    var day = cardnum.substr(12,2);
    var birthday = year+'-'+month+'-'+day;
    return birthday;
}


/*
    2018/03/17
    cookie操作
 */
function setCookie(key, value, iDay) {
    var oDate = new Date();
    oDate.setDate(oDate.getDate() + iDay);
    document.cookie = key + '=' + value + ';expires=' + oDate;

}
function removeCookie(key) {
    setCookie(key, '', -1);//这里只需要把Cookie保质期退回一天便可以删除
}
function getCookie(key) {
    var cookieArr = document.cookie.split('; ');
    for(var i = 0; i < cookieArr.length; i++) {
        var arr = cookieArr[i].split('=');
        if(arr[0] === key) {
            return arr[1];
        }
    }
    return false;
}

